'''
-*-  coding:  utf-8  -*-
Time    : 17:01
Auther  :罗老师
File    :data_util.py
'''
import yaml
import os
import openpyxl
from appium.webdriver.common.mobileby import MobileBy


def get_obj_path():
    """
    获取根目录路径
    """
    return os.path.abspath(__file__).split("common")[0]


def readYaml():
    path = os.path.join(get_obj_path(), r"config\config.yaml")
    with open(path, mode="r", encoding="utf-8") as file:
        data = yaml.load(file, yaml.FullLoader)
    return data


def base():
    sets = {x for x in range(5)}
    print(sets)


def read_excel(excel_path):
    """
    读取excel的数据的方法
    excel_path :用例的excel在data目录下的路径
    """
    path = os.path.join(get_obj_path(), excel_path)
    wb = openpyxl.load_workbook(path)
    sheet = wb["login"]
    indexs = 0
    for i in range(1, sheet.max_column + 1):
        if sheet.cell(1, i).value == "是否执行":
            indexs = i
    row_list = []
    for row in range(1, sheet.max_row + 1):
        if sheet.cell(row, indexs).value == "y" and row > 1:
            column_list = []
            for colum in range(1, sheet.max_column + 1):
                column_list.append(sheet.cell(row, colum).value)
            row_list.append(column_list)
    return row_list


def yuansu_excel(name):
    """
    这是获取化学方程式APP界面元素的的放方法，将元素定位方法和定位值放在表格中，每一个元素做好备注和编号
    name: 传递时必须使用格式为 M*-m8的形式传递
    """
    root_path = os.path.abspath(__file__).split("common")[0]
    excel_path = os.path.join(root_path, r"data\yuansu\huaxuefangchengshi_matix.xlsx")
    M = name.split("-")[0]
    m = name.split("-")[1]
    wb = openpyxl.load_workbook(excel_path)
    sheets = wb[M]
    lst = []
    for row in range(1, sheets.max_row + 1):
        if m == sheets.cell(row, 1).value:
            lst.append(sheets.cell(row, 2).value)
            lst.append(sheets.cell(row, 3).value)

    return tuple(lst)


